﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ZX.HIS.Model;
using ZX.HIS.BLL;
using ZX.HIS.SQLServerDAL;
using ZX.HIS.OracleDAL;
using ZX.HIS.Common;
using System.Text;

namespace ZX.HIS.UI.Controllers
{
    public class RegistTypeController : Controller
    {
        //
        // GET: /RegistType/
        ZX.HIS.BLL.RegistType Rbll = new BLL.RegistType();
        /// <summary>
        /// 添加视图
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View();
        }
        /// <summary>
        /// 添加方法
        /// </summary>
        /// <returns></returns>
        public ActionResult RegistTypeAdd()
        {
            ZX.HIS.Model.RegistType med = new Model.RegistType();
            med.HospitalId = 0;
            HttpCookie myCookie = Request.Cookies["MyCookie"];
            if (myCookie != null)
            {
                if (!String.IsNullOrEmpty(myCookie["HospitalId"]))
                {
                    med.HospitalId = Convert.ToInt32(myCookie["HospitalId"]);
                }
            }
            med.RegistTypeId =Convert.ToInt32( Request["RegistTypeId"]);
            med.RegistTypeName =Request["RegistTypeName"].ToString();
            med.RegistTypeCostPrice =decimal.Parse( Request["RegistTypeCostPrice"]);
            med.RegistTypeSalePrice = decimal.Parse(Request["RegistTypeSalePrice"]);
            int i = Rbll.RegistTypelAdd(med);
            if (i > 0)
            {
                return Content("<script>alert('添加成功');location.href='/RegistType/RegistTypeShow';</script>");
            }
            else
            {
                return Content("<script>alert('添加失败');location.href='/RegistType/RegistTypeShow';</script>");
            }
        }
        /// <summary>
        /// 分页显示
        /// </summary>
        /// <param name="PageIndex"></param>
        /// <param name="PageSize"></param>
        /// <param name="StrOrder"></param>
        /// <param name="StrWhere"></param>
        /// <returns></returns>

        public ActionResult RegistTypeShow()
        {
            ZX.HIS.BLL.RegistType Rbll = new BLL.RegistType();
            string name = "";
            int HospitalId = 0;
            HttpCookie myCookie = Request.Cookies["MyCookie"];
            if (myCookie != null)
            {
                if (!String.IsNullOrEmpty(myCookie["HospitalId"]))
                {
                    HospitalId = Convert.ToInt32(myCookie["HospitalId"]);
                }
            }
            if (!String.IsNullOrEmpty(Request["RegistTypeName"]))
            {
                name = Request["RegistTypeName"].ToString();
                Session["RegistTypeName"] = name;
            }
            PageClass<ZX.HIS.Model.RegistType> pagelist = Rbll.RegistTypeShow(1, 10, name,HospitalId);
            return View(pagelist);

        }
        public ActionResult page(int id, string RegistTypeName)
        {
            string name = "";
            if (Session["RegistTypeName"] != null)
            {
                name = Session["RegistTypeName"].ToString();
            }
            int HospitalId = 0;
            HttpCookie myCookie = Request.Cookies["MyCookie"];
            if (myCookie != null)
            {
                if (!String.IsNullOrEmpty(myCookie["HospitalId"]))
                {
                    HospitalId = Convert.ToInt32(myCookie["HospitalId"]);
                }
            }
            PageClass<ZX.HIS.Model.RegistType> pagelist = Rbll.RegistTypeShow(id, 10, name, HospitalId);
            return View("RegistTypeShow", pagelist);
        }
        /// <summary>
        /// 伪删除
        /// </summary>
        /// <param name="IDS"></param>
        /// <param name="DeparStarte"></param>
        /// <returns></returns>
        public ActionResult RegistTypeUpd(int id)
        {
            ZX.HIS.Model.RegistType mode = new Model.RegistType();
            mode.RegistTypeId = id;
            mode.RegistTypeState = -1;
            ZX.HIS.BLL.DepartInfo DIBLL = new BLL.DepartInfo();
            if (Rbll.RegistTypeUpd(mode) > 0)
            {
                return Content("<script>alert('删除成功');location.href='/RegistType/RegistTypeShow';</script>");
            }
            else
            {
                return Content("<script>alert('删除失败');location.href='/RegistType/RegistTypeShow';</script>");
            }
        }
        /// <summary>
        /// Ajax调用挂号类型
        /// </summary>
        /// <returns></returns>
        public JsonResult FnRegistTypeList()
        {
            int RegistTypeId = 0;
            if (!String.IsNullOrEmpty(Request["RegistTypeId"]))
            {
                RegistTypeId = Convert.ToInt32(Request["RegistTypeId"]);
            }
            ZX.HIS.BLL.RegistType RTBLL = new BLL.RegistType();
            int HospitalId = 1001;
            return Json(RTBLL.RegistTypeList(HospitalId, RegistTypeId));
        }
        /// <summary>
        /// 返回挂号类型类型实体
        /// </summary>
        /// <param name="RegistTypeId"></param>
        /// <returns></returns>
        public JsonResult FnGetRegistTypeModel(int RegistTypeId)
        {
            ZX.HIS.BLL.RegistType RTBLL = new BLL.RegistType();
            return Json(RTBLL.GetRegistTypeModel(RegistTypeId));
        }
        /// <summary>
        /// 修改视图
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public ActionResult RegistTypeUpt(int id)
        {
            ZX.HIS.BLL.RegistType RTBLL = new BLL.RegistType();
            ZX.HIS.Model.RegistType tt = RTBLL.list().Where(p => (p.RegistTypeId == id)).FirstOrDefault();
            ViewData["RegistTypeId"] = tt;
            return View("RegistTypeUpt");
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="DepartName"></param>
        /// <param name="DepartId"></param>
        /// <returns></returns>
        public ActionResult RegistTypeUptmo(ZX.HIS.Model.RegistType mode)
        {
            int i = Rbll.RegistTypeUpt(mode);
            if (i > 0)
            {
                return Content("<script>alert('修改成功');location.href='/RegistType/RegistTypeShow';</script>");
            }
            else
            {
                return Content("<script>alert('修改失败');location.href='/RegistType/RegistTypeShow';</script>");
            }
        }

    }
}
